package com.fangdada.demowebfulx2.handler;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

import java.text.SimpleDateFormat;
import java.util.Date;

import static org.springframework.web.reactive.function.server.ServerResponse.ok;
/**
 * @Author: fd
 * @Date 2021/11/30 17:11
 * @Description: 统一存放处理时间的Handler类
 */
public class TimeHandler {
	public Mono<ServerResponse> getTime(ServerRequest serverRequest) {
		return ok().contentType(MediaType.TEXT_PLAIN)
				.body(Mono.just("Now is " + new SimpleDateFormat("HH:mm:ss").format(new Date())), String.class);
	}
	public Mono<ServerResponse> getDate(ServerRequest serverRequest) {
		return ok().contentType(MediaType.TEXT_PLAIN)
				.body(Mono.just("Today is " + new SimpleDateFormat("yyyy-MM-dd").format(new Date())), String.class);
	}
}
